<include file="Public/header"/>
<style>
    #page-wrapper{padding: 0 10px;}
    .wrapper{padding:0;}
    .ibox-content{padding: 15px 5px;}
    .form-control{display: inline-block;padding: 2px;height: 30px;}
    .input-xs{width: 40px;float:left;}
    .input-sm{width: 70px;}
    .input-s{width: 105px;}
    th{text-align: center;}
    .table > tbody > tr > td{padding: 2px;text-align: center;}
</style>
<div class="panel panel-default row no-borders">
<div class="panel-heading" style="background: #fafafa;">
<h5 class="panel-title text-center"><i class="fa fa-edit"></i> 修改产品信息</h5>
</div>
</div>
<div class="wrapper m-t">
<div class="panel panel-primary">
<div class="panel-heading no-padding">
<div class="panel-options">
<ul class="nav nav-tabs no-borders">
    <li><a href="{:U('Orders/orderUpdate?rid='.$rid)}">订单信息</a></li>
    <li class="active"><a href="{:U('Orders/updateProduct?rid='.$rid)}">产品信息</a></li>
    <li><a href="{:U('Orders/updateCraft?rid='.$rid)}">工序信息</a></li>
    <li><a href="{:U('Orders/updateMaterial?rid='.$rid)}">原材料信息</a></li>
</ul>
</div>
</div>
<div class="panel-body">
<button class="btn btn-success col-lg-2 m-b" id="addPro">
<i class="glyphicon glyphicon-plus"></i> 添加产品
</button>
<div class="clearfix"></div>
<div class="tab-content">
<div class="tab-pane active">
    <form class="form-horizontal" id="formvalidate" action="{:U('Orders/updateProduct?rid='.$rid)}"
          method="post">

        <div style="width: 100%; overflow-x: auto;">
            <table class="table-striped table table-bordered">
                <thead>
                <tr>
                    <th>商品分类</th>
                    <th>商品名称</th>
                    <th>门洞尺寸</th>
                    <th>门扇规格</th>
                    <th>立板规格</th>
                    <th>帽头规格</th>
                    <th>工艺分类</th>
                    <th>工艺技术</th>
                    <th>数量</th>
                    <th>线条长度</th>
                    <th>线条分类</th>
                    <th>线条型号</th>
                    <th>线条数量</th>
                    <th>颜色</th>
                    <th>折扣</th>
                    <th>单价</th>
                    <th>总价</th>
                    <th>备注</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="pro">
                <volist name="_list" id="lvo" >
                <tr>
                    <td>
                        <select name="product_cate[]" onchange="productlist(this,this.value)" class="form-control input-s">
                            <option value="">请选择</option>
                            <volist name="plist" id="vo">
                                <if condition=" $lvo.product_cate eq $vo.id ">
                                    <option selected="selected" value="{$vo.id}">{$vo.cate_name}</option>
                                    <else/>
                                    <option value="{$vo.id}">{$vo.cate_name}</option>
                                </if>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <select name="productName[]" class="form-control input-s">
                            <volist name="lvo['orderproduct']" id="vs">

                                <if condition="$lvo.productname eq $vs.cate_name ">
                                    <option value="{$vs.id}" selected="selected">{$vs.cate_name}</option>
                                    <else/>
                                    <option value="{$vs.id}">{$vs.cate_name}</option>
                                </if>

                            </volist>
                        </select>
                    </td>
                    <td>
                        <input type="text" value="{$lvo.dooropeningsize}"  onblur="opening(this,this.value)" name="doorOpeningSize[]"  class="form-control input-s" placeholder="cm*cm*cm"/>
                    </td>
                    <td>
                        <input type="text" value="{$lvo.doorleafstandard}"  id="msg" name="doorLeafStandard[]" class="form-control input-s" placeholder="cm*cm=cm"/>
                    </td>
                    <td>
                        <input type="text" value="{$lvo.verticalplate}"  name="verticalPlate[]"  class="form-control input-s" placeholder="cm*cm=cm"/>
                    </td>
                    <td>
                        <input type="text" value="{$lvo.cropupstandard}"  name="cropupStandard[]"  class="form-control input-s" placeholder="cm*cm=cm"/>
                    </td>
                    <td>
                        <select class="form-control input-s" name="craftcate[]" onchange="craflist(this,this.value)">
                            <option value="">请选择</option>
                            <volist name="cre" id="vo">
                                <if condition="$vo.id == $lvo.craftcate ">
                                    <option selected="selected" value="{$vo.id}">{$vo.craft_name}</option>
                                    <else/>
                                    <option value="{$vo.id}">{$vo.craft_name}</option>
                                </if>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <select name="craft_name[]" class="form-control input-s">
                            <volist name="lvo['crafts']" id="vs">

                                <if condition="$lvo.craft_name eq $vs.craft_name ">
                                    <option value="{$vs.id}" selected="selected">{$vs.craft_name}</option>
                                    <else/>
                                    <option value="{$vs.id}">{$vs.craft_name}</option>
                                </if>


                            </volist>
                        </select>
                    </td>
                    <td>
                        <input type="text" value="{$lvo.numbers}" name="Numbers[]"  class="form-control input-xs"/>
                    </td>
                    <td>
                        <select name="linelength[]" class="form-control input-s">
                            <option value="">选择</option>
                            <volist name="lenth" id="vo">
                                <if condition="$vo.lenth_value == $lvo.linelength ">
                                    <option selected="selected" value="{$vo.lenth_value}">{$vo.lenth_value}</option>
                                    <else/>
                                    <option value="{$vo.lenth_value}">{$vo.lenth_value}</option>
                                </if>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <select class="form-control input-s" name="line_cate[]" onchange="linelist(this,this.value)">
                            <option value="">请选择</option>
                            <volist name="line" id="vo">
                                <if condition="$vo.id == $lvo.line_cate ">
                                    <option selected="selected" value="{$vo.id}">{$vo.line_name}</option>
                                    <else/>
                                    <option value="{$vo.id}">{$vo.line_name}</option>
                                </if>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <select name="linetype[]" class="form-control input-s">
                            <volist name="lvo['linetypes']" id="vs">
                                <if condition="$lvo.linetype eq $vs.line_name ">
                                    <option value="{$vs.id}" selected="selected">{$vs.line_name}</option>
                                    <else/>
                                    <option value="{$vs.id}">{$vs.line_name}</option>
                                </if>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <input name="wireNumber[]" value="{$lvo.wirenumber}"  type="text" class="form-control input-sm"/>
                    </td>
                    <td>
                        <select name="color[]" class="form-control input-s">
                            <option value="">请选择</option>
                            <volist name="colors" id="vo">
                                <if condition="$lvo.color eq $vo.color_number ">
                                    <option selected="selected" value="{$vo.color_number}">{$vo.color_number}</option>
                                    <else/>
                                    <option value="{$vo.color_number}">{$vo.color_number}</option>
                                </if>
                            </volist>
                        </select>
                    </td>
                    <td>
                        <input type="text" value="{$lvo.discount}" name="discount[]" class="form-control input-xs"/>
                    </td>
                    <td>
                        <input onblur="prices(this,this.value)"  value="{$lvo.price}" type="text" name="price[]"  class="form-control input-xs"/>
                    </td>
                    <td>
                        <input type="text"  value="{$lvo.totalprice}" name="totalPrice[]" class="form-control input-sm"/>
                    </td>
                    <td>
                        <input type="text" value="{$lvo.remark}" name="remark[]" class="form-control input-sm"/>
                    </td>
                    <td>
                        <div class="btn-group" style="width: 40px;">
                            <a class="confirms ajax-get" href="{:U('Orders/pdel?id='.$lvo['id'])}">
                                <button class="btn btn-danger btn-sm deletBtn" type="button">x</button>
                            </a>

                        </div>
                    </td>
                </tr>
                    <input type="hidden" name="id[]" value="{$lvo.id}" />
                </volist>
                </tbody>
            </table>
        </div>


        <div class="form-group">
            <input type="submit" target-form="form-horizontal"
                   class="ajax-post btn btn-primary col-lg-1 col-lg-push-5 m-t-lg" value="提交"/>
        </div>
    </form>
</div>
</div>
</div>
</div>
</div>
<table style="display: none;">

    <tr id="padd" >
    <td>
        <select name="product_cate[]" onchange="productlist(this,this.value)" class="form-control input-s">
            <option value="">请选择</option>
            <volist name="plist" id="vo">
                <option value="{$vo.id}">{$vo.cate_name}</option>
            </volist>
        </select>
    </td>
    <td>
        <select name="productName[]" class="form-control input-s">
            <option value="">请选择</option>
        </select>
    </td>
    <td>
        <input type="text" onblur="opening(this,this.value)" name="doorOpeningSize[]"  class="form-control input-s" placeholder="cm*cm*cm"/>
    </td>
    <td>
        <input type="text"  name="doorLeafStandard[]" class="form-control input-s" placeholder="cm*cm=cm"/>
    </td>
    <td>
        <input type="text" name="verticalPlate[]"  class="form-control input-s" placeholder="cm*cm=cm"/>
    </td>
    <td>
        <input type="text" name="cropupStandard[]"  class="form-control input-s" placeholder="cm*cm=cm"/>
    </td>
    <td>
        <select class="form-control input-s" name="craftcate[]" onchange="craflist(this,this.value)">
            <option value="">请选择</option>
            <volist name="cre" id="vo">
                <option value="{$vo.id}">{$vo.craft_name}</option>
            </volist>
        </select>
    </td>
    <td>
        <select name="craft_name[]" class="form-control input-s">
            <option value="">请选择</option>
        </select>
    </td>
    <td>
        <input type="text" value="1" name="Numbers[]"  class="form-control input-xs"/>
    </td>
    <td>
        <select name="linelength[]" class="form-control input-s">
            <option value="">选择</option>
            <volist name="lenth" id="vo">
                <option value="{$vo.lenth_value}">{$vo.lenth_value}</option>
            </volist>
        </select>
    </td>
    <td>
        <select class="form-control input-s" name="line_cate[]" onchange="linelist(this,this.value)">
            <option value="">请选择</option>
            <volist name="line" id="vo">
                <option value="{$vo.id}">{$vo.line_name}</option>
            </volist>
        </select>
    </td>
    <td>
        <select name="linetype[]" class="form-control input-s">
            <option value="">请选择</option>
        </select>
    </td>
    <td>
        <input name="wireNumber[]" value="1" type="text" class="form-control input-sm"/>
    </td>
    <td>
        <select name="color[]" class="form-control input-s">
            <option value="">请选择</option>
            <volist name="colors" id="vo">
                <option value="{$vo.color_number}">{$vo.color_number}</option>
            </volist>
        </select>
    </td>
    <td>
        <input type="text" value="1"  name="discount[]" class="form-control input-xs"/>
    </td>
    <td>
        <input onblur="prices(this,this.value)"  type="text" name="price[]"  class="form-control input-xs"/>
    </td>
    <td>
        <input type="text"  name="totalPrice[]" class="form-control input-sm"/>
    </td>
    <td>
        <input type="text" name="remark[]" class="form-control input-sm"/>
    </td>
    <td>
        <div class="btn-group" style="width: 40px;">
            <button class="btn btn-danger btn-sm deletBtn" type="button">x</button>
        </div>
    </td>
</tr>

</table>

<include file="Public/footer"/>
<script src="__PUBLIC__/Admin/js/tianchen.js"></script>
<script src="__PUBLIC__/Admin/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script>
    //新增商品栏
    var proHTML=$('#padd').prop('outerHTML');
    $('#addPro').click(function(){
        $('#pro').append(proHTML);
    });

    $(function(){
        var addHtml=$('table tbody tr:first').prop('outerHTML');
        $('body').on('click','.addBtn',function(){
            $('table tbody tr:last').after(addHtml);
        }).on('click','.deletBtn',function(){
            $(this).parents('tr').remove();
        });
    });

    //门扇、立板、冒头规格的参数
    var ms_length = '';//门扇长
    var ms_witch = '';//门扇宽
    var ms_value = '';//门扇默认值
    var lb_length = '';//立板长
    var lb_witch = '';//立板宽
    var lb_value = '';//立板默认值
    var mt_length = '';//冒头长
    var mt_witch = '';//冒头宽
    var mt_value = '';//冒头默认值

    //获取商品信息
    function productlist(that, pid) {
        if(pid==''){
            $(that).parents('tr').find("[name='productName[]']").html('<option value="">请选择</option>');
            return false;
        }
        //根据商品分类id获取订单基础参数
        $.post("{:U('Login/getparma')}",{pid:pid},function (data) {
            if(data.state=='error'){
                layer.alert(data.info);
                return false;
            }else{
                var info=data.info;
                ms_length=parseInt(info.ms_length);
                ms_witch=parseInt(info.ms_witch);
                ms_value=info.ms_value;
                lb_length=parseInt(info.lb_length);
                lb_witch=parseInt(info.lb_witch);
                lb_value=info.lb_value;
                mt_length=parseInt(info.mt_length);
                mt_witch=parseInt(info.mt_witch);
                mt_value=info.mt_value;
            }
        })

        var ptext = '';
        $.post("{:U('OrderSet/productList')}", {pid: pid}, function (data) {
            if(data !== ''){
                $.each(data, function (k, v) {
                    ptext += "<option value='" + v.cate_name + "'>" + v.cate_name + "</option>";
                })
            }
            $(that).parents('tr').find("[name='productName[]']").html(ptext);
        })
    }

    //通过门洞尺寸计算其他规格
    function opening(that, valid) {
        valid = valid.NoSpace();//门洞规格
        var re = valid.split('*');
        var lengths = parseInt(re[0]);
        var witchs = parseInt(re[1]);

        var ms = (lengths + ms_length) + '*' + (witchs + ms_witch) + '=' + ms_value;//门扇规格
        var lb = (lengths + lb_length) + '*' + (witchs + lb_witch) + '=' + lb_value;//立板规格
        var mt = (lengths + mt_length) + '*' + (witchs + mt_witch) + '=' + mt_value;//冒头规格
        $(that).parents('tr').find("[name='doorLeafStandard[]']").val(ms);
        $(that).parents('tr').find("[name='verticalPlate[]']").val(lb);
        $(that).parents('tr').find("[name='cropupStandard[]']").val(mt);

    }
    //获取工艺信息
    function craflist(that, pid) {
        if(pid == ''){
            $(that).parents('tr').find("[name='craft_name[]']").html('<option value="">请选择</option>');
            return false;
        }
        var ctext = '';
        $.post("{:U('OrderSet/craftsList')}", {pid: pid}, function (data) {
            $.each(data, function (k, v) {
                ctext += "<option value='" + v.craft_name + "'>" + v.craft_name + "</option>";
            })
            $(that).parents('tr').find("[name='craft_name[]']").html(ctext);
        })
    }
    //获取线条型号信息
    function linelist(that, pid) {
        if(pid == ''){
            $(that).parents('tr').find("[name='linetype[]']").html('<option value="">请选择</option>');
            return false;
        }
        var ltext = '';
        $.post("{:U('OrderSet/linelist')}", {pid: pid}, function (data) {
            $.each(data, function (k, v) {
                ltext += "<option value='" + v.line_name + "'>" + v.line_name + "</option>";
            })

            $(that).parents('tr').find("[name='linetype[]']").html(ltext);
        })
    }
    //计算总价
    function prices(that, pval) {
        var price = parseFloat(pval);//单价
        var number = $(that).parents('tr').find("[name='Numbers[]']").val();
        var discount = $(that).parents('tr').find("[name='discount[]']").val();
        $(that).parents('tr').find("[name='totalPrice[]']").val(price * number * parseFloat(discount));
    }
    //工序操作
    var gongyiHTML=$('.gongyibox').prop('outerHTML');
    $("body").on('click','.addGongyi',function(){
        $('#gy').append(gongyiHTML);
        $('.removeGongyi:not(.removeGongyi:first)').removeClass('hidden');
    }).on('click','.removeGongyi',function(){
        $(this).parents('.gongyibox').remove();
    });

</script>